#!/bin/bash
pdb="${1:-none}"
scalebar="${2:-none}"
out="${3:-none}"
[[ -e "$pdb" ]] || exit 1
[[ -e "$scalebar" ]] || exit 1
[[ "$out" == "none" ]] && exit 1

tmp=$(mktemp)
trap 'rm -rf ${tmp:-NONE}*' EXIT
#Create the rasmol script

# turn axis, angle


cat <<__EOF__ > "${tmp}.pml"
set auto_zoom, on
load $pdb
#bg_color white
#set ray_opaque_background, off
set ray_opaque_background, on
spectrum b, blue_white_red, minimum=0, maximum=100
show cartoon
#color purple, ss h
#color yellow, ss s

ray 1200,1200
png ${tmp}-pm.png

turn x, 90
ray 1200,1200
png ${tmp}-pm-x.png

turn x, -90
turn y, 90
ray 1200,1200
png ${tmp}-pm-y.png

turn y, -90
turn z, 90
ray 1200,1200
png ${tmp}-pm-z.png

quit
__EOF__
# execute PyMol
pymol -qxci "${tmp}.pml"

# assemble the 4 pictures
magick montage -background '#999' -geometry +2+2 "${tmp}-pm.png" "${tmp}-pm-x.png" "${tmp}-pm-y.png" "${tmp}-pm-z.png" "${tmp}-montage.png"
magick composite -gravity SouthEast -geometry +4+4 "$scalebar" "${tmp}-montage.png" "$out" 

